<template>
  <div class="table-page-search-wrapper">
    <el-form :model="searchForm" ref="searchForm" label-width="100px" class="demo-ruleForm">
      <el-row :gutter="10">
        <el-col :md="8" :sm="12" :xs="24">
          <el-form-item label="商品名称:">
            <a-input v-model="searchForm.goodsName" placeholder="请输入商品名称" />
          </el-form-item>
        </el-col>
        <el-col :md="8" :sm="12" :xs="24">
          <el-form-item label="商品条码:">
            <a-input v-model="searchForm.barCode" placeholder="请输入条码或后四位" />
          </el-form-item>
        </el-col>
        <el-col :md="8" :sm="12" :xs="24">
          <el-form-item label="商品分类:">
            <a-cascader
              :options="categoryIdList"
              v-model="pids"
              change-on-select
              placeholder="请选择商品类目"
            ></a-cascader>
          </el-form-item>
        </el-col>
        <!-- <el-col :md="8" :sm="12" :xs="24">
          <el-form-item label="实物库存:">
            <a-input v-model="searchForm.low" placeholder="最低" style="width:48%" />
            <span>-</span>
            <a-input v-model="searchForm.hight" placeholder="最高" style="width:48%" />
          </el-form-item>
        </el-col>-->
        <el-col :md="8" :sm="12" :xs="24">
          <div style="margin-left:30px">
            <a-button type="primary" icon="search" @click="searchAction()">查询</a-button>
            <a-button @click="resetSearch()" icon="delete" style="margin-left: 8px;">重置</a-button>
          </div>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>
<script>
import { shopgoodscategory } from '@/api/shop/stock/list.js'
export default {
  name: 'search',
  data() {
    return {
      zhuangtaiList: [
        {
          label: '停用',
          value: 0,
        },
        {
          label: '启用',
          value: 1,
        },
      ], //zhaungt
      yetaiList: [
        //商品业态
        {
          label: '商超',
          value: '01',
        },
        {
          label: '咖吧',
          value: '02',
        },
        {
          label: '洗衣',
          value: '03',
        },
        {
          label: '家政',
          value: '04',
        },
      ],
      searchForm: {
        
      },
      djztList: [],
      categoryIdList: [],
      pids: [],
    }
  },
  mounted() {
    this.getLeiMu()
  },
  methods: {
    searchAction() {
      //执行搜索
      if (this.pids) {
        if (this.pids.length > 1) {
          //商品类目
          this.searchForm.categoryId = this.pids[1]
          this.searchForm.pid = this.pids[0]
        } else {
          this.searchForm.categoryId = this.pids[0]
          this.searchForm.pid = this.pids[0]
        }
      }
      this.$emit('search')
    },
    resetSearch() {
      this.searchForm = {}
      this.$emit('resetSearch')
    },
    getSearchForm() {
      //获取高级搜索条件
      return {
        ...this.searchForm,
      }
    },
    getLeiMu() {
      shopgoodscategory({ businessType: '' }).then((val) => {
        //商品类目
        let data = val.data
        console.log(data)
        this.categoryIdList = data.map((item) => {
          return {
            value: item.categoryId,
            label: item.categoryName,
            children: item.children.map((items) => {
              return {
                value: items.categoryId,
                label: items.categoryName,
              }
            }),
          }
        })
      })
    },
  },
}
</script>


<style lang="less">
</style>>
